package server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-21
 */
public class EchoServiceHandler implements Runnable {
	private Socket s;

	public EchoServiceHandler(Socket s) {
		this.s = s;
	}

	public void run() {
		PrintWriter pw = null;
		BufferedReader in = null;
		try {
			in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); // 通过这个socket打开一个输出流
			while (true) { // 循环读取
				String req = in.readLine();
				pw.println(req);
				pw.flush();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				pw.close();
				s.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}